﻿using System;
using System.IO;

namespace Com.VikingErik.Mvc.ResumingDownloads
{
    public class ResumableFileResult : ResumableDownloadResult
    {
        private FileInfo MediaFile;

        public ResumableFileResult(ResumableDownloadRequest resumableDownloadRequest, FileInfo mediaFile)
            : this(resumableDownloadRequest, mediaFile, GetMIMEType(mediaFile.Extension.ToLower()))
        {
        }

        public ResumableFileResult(ResumableDownloadRequest resumableDownloadRequest, FileInfo mediaFile, string contentType)
            : base(resumableDownloadRequest, contentType)
        {
            MediaFile = mediaFile;
        }

        protected override Stream FileContent
        {
            get
            {
                return MediaFile.OpenRead();
            }
        }

        protected override DateTimeOffset? LastModified
        {
            get
            {
                return MediaFile.LastWriteTimeUtc;
            }
        }
    }
}
